#ifndef CLIENT_HPP
#define CLIENT_HPP

#include<string>
#include<xnetwork/XTcpSocket.hpp>
#include<xsignal/signal.hpp>
#include<xsignal/sigReciver.hpp>
class TcpClient:public sigReciver{
public:
    TcpClient(std::string ip,unsigned int port):m_ip(ip),m_port(port){
        m_socket = new XTcpSocket;
        m_socket->connectToServer(ip,port);
        AttachSignalSlot();
    }
    ~TcpClient(){}

    void AttachSignalSlot()
    {
        connect(m_socket, &XTcpSocket::sig_read, this, &TcpClient::slotDealRecive, SIG::connectType::directConnection);
        connect(m_socket, &XTcpSocket::sig_connect, this, [](){ std::cout << "XTcpSocket connect!" << std::endl; });
        connect(m_socket, &XTcpSocket::sig_disconnect, this, [](){ std::cout << "XTcpSocket disconnect!" << std::endl; });
    }
private:
    void slotDealRecive(char* buf,int len){
        std::cout<<"len:"<<len<<" buf:"<<std::string(buf,len)<<std::endl;
    }
private:
    XTcpSocket* m_socket;
    std::string m_ip;
    unsigned int m_port;
};
#endif
   